// 模板设计模式

var Beverage = function () {};

Beverage.prototype.boilWater = function () {
    console.log("把水煮开")
}

Beverage.prototype.brewWater = function () {
    throw new Error("子类必须重写该方法");
}

Beverage.prototype.pourInCup = function () {
    throw new Error("子类必须重写该方法");
}

Beverage.prototype.addCondiments = function () {
    throw new Error("子类必须重写该方法");
}
// 钩子方法：增强模板的可扩展性
Beverage.prototype.customerWantsCondiments = function () {
    return true;
}

// 模板方法：为子类定下一个大的运行流程，具体的实现交给子类来做
Beverage.prototype.init = function () {
    this.boilWater();
    this.brewWater();
    this.pourInCup();
    if (this.customerWantsCondiments) {
        this.addCondiments();
    }
}

var Coffee = function () {};
Coffee.prototype = new Beverage();

Coffee.prototype.brewWater = function () {
    console.log("冲泡咖啡")
}

Coffee.prototype.pourInCup = function () {
    console.log('导入杯中')
}

Coffee.prototype.customerWantsCondiments = function () {
    return window.confirm("需要加东西吗？");
}

Coffee.prototype.addCondiments = function () {
    console.log("加牛奶")
}

var coffee = new Coffee();
coffee.init();